package lab.gene.action;

import java.util.Date;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lab.gene.service.impl.GenePrepFinalsServiceImpl;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

public class UpdateGenePrepFinalsAction extends ActionSupport implements ServletResponseAware, ServletRequestAware {
	
	private static final long serialVersionUID = 1L;
	protected HttpServletResponse servletResponse;  
	@Override   
	public void setServletResponse(HttpServletResponse servletResponse) {   
		this.servletResponse = servletResponse;   
	}   
	
	protected HttpServletRequest servletRequest;   
	@Override   
	public void setServletRequest(HttpServletRequest servletRequest) {   
		this.servletRequest = servletRequest;   
	} 
	
	private String geneName;
	private String type;
	private Date date1;
	private Date date2;
	private Date date3;
	private String exsize1;
	private String exsize2;
	private String pcr1;
	private String pcr2;
	private String checked1;
	private String checked2;
	private String checked3;
	private String comments;
	private String userName;
	private Date dateModified;
	
	public String execute() {
		String result = null;
		Cookie[] cookies = servletRequest.getCookies();
		String cookieName = "LabUser";
		userName = null;
		if (cookies != null) {
			for (int i = 0; i < cookies.length; i++) {
				if (cookies[i].getName().equals(cookieName)) {
					userName = cookies[i].getValue();
					break;
				}
			}
		}
		
		System.out.println("Prep Finals1");
		GenePrepFinalsServiceImpl service = new GenePrepFinalsServiceImpl();
		int esize1 = 0, esize2 = 0;
		System.out.println("Prep Finals2");
		esize1 = (exsize1 != null && exsize1.length() != 0) ? Integer.valueOf(exsize1) : 0;
		esize2 = (exsize2 != null && exsize2.length() != 0) ? Integer.valueOf(exsize2) : 0;
		System.out.println("Prep Finals3");
		service.addGenePrepFinals(geneName, type, date1, date2, date3, pcr1, pcr2, esize1, esize2, checked1, checked2, checked3, comments, userName);
		
		switch (type){
		case "B":
			result = "successB";
			break;
		case "C":
			result = "successC";
			break;
		case "D":
			result = "successD";
			break;
		}
		return result;
	}
	public String getGeneName() {
		return geneName;
	}
	public void setGeneName(String geneName) {
		this.geneName = geneName;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Date getDate1() {
		return date1;
	}
	public void setDate1(Date date1) {
		this.date1 = date1;
	}
	public Date getDate2() {
		return date2;
	}
	public void setDate2(Date date2) {
		this.date2 = date2;
	}
	public Date getDate3() {
		return date3;
	}
	public void setDate3(Date date3) {
		this.date3 = date3;
	}
	
	public String getExsize1() {
		return exsize1;
	}
	public void setExsize1(String exsize1) {
		this.exsize1 = exsize1;
	}
	public String getExsize2() {
		return exsize2;
	}
	public void setExsize2(String exsize2) {
		this.exsize2 = exsize2;
	}
	public String getPcr1() {
		return pcr1;
	}
	public void setPcr1(String pcr1) {
		this.pcr1 = pcr1;
	}
	public String getPcr2() {
		return pcr2;
	}
	public void setPcr2(String pcr2) {
		this.pcr2 = pcr2;
	}
	public String getChecked1() {
		return checked1;
	}
	public void setChecked1(String checked1) {
		this.checked1 = checked1;
	}
	public String getChecked2() {
		return checked2;
	}
	public void setChecked2(String checked2) {
		this.checked2 = checked2;
	}
	public String getChecked3() {
		return checked3;
	}
	public void setChecked3(String checked3) {
		this.checked3 = checked3;
	}
	public String getComments() {
		return comments;
	}
	public void setComments(String comments) {
		this.comments = comments;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public Date getDateModified() {
		return dateModified;
	}
	public void setDateModified(Date dateModified) {
		this.dateModified = dateModified;
	}
	
}
